package com.view.cn.mvprxjava;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.TextView;

import com.view.cn.mvprxjava.fragment.ListFragment;
import com.view.cn.mvprxjava.utils.FragmentUtils;
import com.view.cn.mvprxjava.utils.LogUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {

	@Bind(R.id.tv)
	TextView mTv;
	@Bind(R.id.tv2)
	TextView mTv2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ButterKnife.bind(this);
		FragmentUtils.replaceFragment(this, ListFragment.newInstance(), ListFragment.TAG);

		initEvent();
	}

	private void initEvent() {
//		mTv.setOnClickListener(new View.OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				Intent intent = new Intent(MainActivity.this, SecondActivity.class);
//				startActivity(intent);
//			}
//		});

		String a = "aaa";//匿名内部类在调用外面的局部变量必须是final修饰的，但是使用lambda表达式不需要
		mTv.setOnClickListener(v -> {
			Intent intent = new Intent(this, SecondActivity.class);
			startActivity(intent);

			LogUtils.e(TAG, a);
		});

		mTv2.setOnClickListener(v -> {
			Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contanier);
			if (fragment instanceof ListFragment) {

			} else {
				getSupportFragmentManager().popBackStack();
			}
		});
	}
}
